#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import getpass
from AllFuncs import *

if __name__ == "__main__":
	flag = 1

	consumer_key= "2998871798"
	consumer_secret ="049fe45ea21fb9aa1de9c301bd5c3688"

	test = allFuncs()

	if(flag):
		username = raw_input("		输入用户名：")
		passwd = getpass.getpass("		输入%s的密码："%username)
		token = test.oAuth(username, passwd)
	else:
		token = test.auth(consumer_key, consumer_secret)

	user_screen_name = test.user_login()
	print u"			登录成功\n			欢迎你，" + user_screen_name

	test.setToken(token.key, token.secret)
	test.setAccessToken(token.key, token.secret)

	while True:
		print '\n			目前能提供的功能\n			(错误选项将回到本界面)'
		print '################################################################################'
		print '			1.发表新状态'
		print '			2.查看所有人最新的5条状态'
		print '			3.查看某个用户最近5条状态'
		print '			4.回复某条状态'
		print '			5.上传一张图片'
		print '			6.看看谁提到我了'
		print '			7.查看我的好友'
		print '			8.查看谁关注了我'
		#print '			9.删除某条状态（此功能暂时无效）'
		print '			0.退出'
		print '################################################################################'

		choice = raw_input("			选择的操作：")

		if choice == '1':
			message = raw_input("想说些什么(140字以内)：")
			test.update(message)
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '2':
			test.friends_timeline()
			while True:
				flag=raw_input('			按c继续查看之前5条状态，直接确定返回上级菜单:')
				print "\n"
				if flag=='':
					break
				elif flag=='c':
					test.home_timeline()

		elif choice == '3':
			user = raw_input("输入要查看的用户名（留空表示查看自己的）：")
			if user == '':
				user = user_screen_name

			print "			" + user,
			print u"的个人时间线\n"
			test.user_timeline(user)
			while True:
				flag=raw_input('			按c继续查看之前5条状态，直接确定返回上级菜单:')
				print "\n"
				if flag=='':
					break
				elif  flag=='c':
					test.user_timeline_continue(user)

		elif choice == '4':
			comid = raw_input("输入要回复的状态的id：")
			com = raw_input("输入对这条状态要说的：")
			test.comment(comid, com)
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '5':
			filename = raw_input("输入图片的完整路径和文件名“如/root/1.jpg”：")
			statu = raw_input("对这张图片要说什么：")
			test.upload(filename, statu)
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '6':
			test.mentions()
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '7':
			test.friends()
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '8':
			test.followers()
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			if flag=='':
				continue

		elif choice == '9':#提示oauth签名值非法，估计api问题
			pass
			did = raw_input("输入要删除的状态的id：")
			test.destroy_status(did)
			flag=raw_input('			直接确定返回上级菜单:')
			print "\n"
			#if flag=='':
				#continue

		elif choice == '0':
			print "			退出程序\n"
			sys.exit(1)
